#include "wxsimagepanel.h"

namespace
{


    #include "wxImagePanel16.xpm"
    #include "wxImagePanel32.xpm"

    wxsRegisterItem<wxsImagePanel> Reg(
        _T("wxImagePanel"),             			
        wxsTContainer,                  				
        _T("wxWindows"),                			
        _T("Ron Collins"),              				
        _T("rcoll@theriver.com"),       		
        _T(""),                         						
        _T("Contrib"),              						
        60,                             							
        _T("ImagePanel"),               			
        wxsCPP,                         					
        1, 0,                           							
        wxBitmap(wxImagePanel32_xpm),	
        wxBitmap(wxImagePanel16_xpm),	
        false);                         						


    WXS_ST_BEGIN(wxsImagePanelStyles,_T("wxRAISED_BORDER|wxTAB_TRAVERSAL"))
        WXS_ST_CATEGORY("wxImagePanel")
        WXS_ST_DEFAULTS()
    WXS_ST_END()

    WXS_EV_BEGIN(wxsImagePanelEvents)
        WXS_EV_DEFAULTS()
    WXS_EV_END()
}



wxsImagePanel::wxsImagePanel(wxsItemResData* Data):
    wxsContainer(
        Data,
        &Reg.Info,
        wxsImagePanelEvents,
        wxsImagePanelStyles) {
    mImage   = _("<none>");
    mStretch = false;
}


wxsImagePanel::~wxsImagePanel() {

}


void wxsImagePanel::OnBuildCreatingCode() {
wxString    vname;
wxString    iname;
wxsImage    *image;
wxString    tt;


    if (GetLanguage() != wxsCPP) wxsCodeMarks::Unknown(_T("wxsImagePanel"),GetLanguage());


    vname = GetVarName();


    image = (wxsImage *) wxsImageListEditorDlg::FindTool(this, mImage);

    if (image == NULL) {
        iname = wxEmptyString;
    }
    else {
        iname  = image->GetVarName();
        iname += _("_BMP");
    };


    AddHeader(_("\"wx/wxImagePanel.h\""), GetInfo().ClassName, 0);


    Codef(_T("%C(%W, %I, %P, %S, %T, %N);\n"));


    Codef(_T("%ASetStretch(%b);\n"), mStretch);



    if (iname.Length() > 0) {
	
		tt.Printf(_("// Set the bitmap for %s.\n"), vname.wx_str());
        AddEventCode(tt);

#if wxCHECK_VERSION(3, 0, 0)
        tt.Printf(_T("%s->SetBitmap(*%s);\n"), vname.wx_str(), iname.wx_str());
#else
        tt.Printf(_T("%s->SetBitmap(*%s);\n"), vname.c_str(), iname.c_str());
#endif
        AddEventCode(tt);
    };


    BuildSetupWindowCode();


    AddChildrenCode();
}


wxObject* wxsImagePanel::OnBuildPreview(wxWindow* Parent, long Flags) {
wxImagePanel    *ap;
wxsImage        *image;
wxBitmap        bmp;


    ap = new wxImagePanel(Parent, GetId(), Pos(Parent), Size(Parent), Style());
    if (ap == NULL) return NULL;


    image = (wxsImage *) wxsImageListEditorDlg::FindTool(this, mImage);


    if (image != NULL) {
        bmp = ((wxsImage *) image)->GetPreview();
        ap->SetBitmap(bmp);
    };


    ap->SetStretch(mStretch);


    SetupWindow(ap, Flags);


    AddChildrenPreview(ap, Flags);


    return ap;
}


void wxsImagePanel::OnEnumContainerProperties(cb_unused long Flags) {
static wxString         sImageNames[128];
static const wxChar    *pImageNames[128];

int                     i,n,k;
wxsItemResData         *res;
wxsTool                *tool;
wxString                ss, tt;



    res = GetResourceData();
    n = 0;
    sImageNames[n] = _("<none>");
    pImageNames[n] = (const wxChar *) sImageNames[n];
    n += 1;
    k = res->GetToolsCount();
    for(i=0; i<k; i++) {
        tool = res->GetTool(i);
        ss = tool->GetUserClass();

        if ((ss == _T("wxImage")) && (n < 127)) {
            ss = tool->GetVarName();
            sImageNames[n] = ss;
            pImageNames[n] = (const wxChar *) sImageNames[n];
            n += 1;
        };
    };
    pImageNames[n] = NULL;

    WXS_EDITENUM(wxsImagePanel, mImage, _("Image"), _T("image"), pImageNames, _("<none>"))


    WXS_BOOL(wxsImagePanel, mStretch, _("Stretch"), _T("stretch"), false);
};







